#include <unistd.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#include "full.h"
#define DEFAULT_TTY "/dev/ttyS3"
#define END '#'

std::vector<std::queue<uint8_t> > result_vec;
std::queue<uint8_t> result_queue;
cssl_t *st;
bool flag = false;
void process() {
  static std::queue<uint8_t> tmp;
  while (!result_queue.empty()) {
    tmp.push(result_queue.front());
    if (result_queue.front() == (uint8_t)END) {
      result_vec.push_back(tmp);
      while (!tmp.empty()) tmp.pop();
    }
  }
  return;
}

void cb(int id, uint8_t *buffer, int len) {
  // for(int i=0;i<len;i++){
  // 	if(buffer[i]=='\0')
  // 		result_queue.push(' ');
  // 	else
  // 		result_queue.push(buffer[i]);
  // }
  // process();
  for (int i = 0; i < len; i++) printf("%d", buffer[i]);
}

int main() {
  cssl_start();
  st = cssl_open(DEFAULT_TTY, cb, 0, 921600, 8, 0, 1);
  while (1) {
    cssl_drain(st);
    if (flag) break;
  }
  cssl_close(st);
}